package com.szy.assembly;


import java.io.Serializable;
import java.util.ArrayList;

public class Program implements Serializable {
    public ArrayList<Instruction> instructionList;



    public Program(){
        instructionList=new ArrayList<Instruction>();
    }

    public static Program getDefaultProgram(){
        Program program=new Program();
        program.setInstruction(0,new Instruction(InstructionEnum.J,0));
        return program;
    }
    public Instruction setInstruction(int index,Instruction ins){
        int dif=index-instructionList.size();
        if(dif > 0){
            for(int i=0;i<dif;i++){
                instructionList.add(new Instruction(InstructionEnum.NOP));
            }
            instructionList.add(ins);
        }else if(dif == 0){
            instructionList.add(ins);
        }else{
            instructionList.set(index,ins);
        }
        return ins;
    }

    public Instruction getInstruction(int index){
        return instructionList.get(index);
    }
    public int getProgramLength(){
        return instructionList.size();
    }

    public void clear(){
        instructionList.clear();
    }

}
